Skip to content

Conversation

@xSetech
Copy link
Contributor

@xSetech xSetech commented Nov 7, 2025

The python() method was hardcoded to return /usr/bin/python3 on macOS, ignoring the build.python config option. This change respects the config while maintaining the system Python as the default.

The `python()` method was hardcoded to return `/usr/bin/python3` on
macOS, ignoring the `build.python` config option. This change respects
the config while maintaining the system Python as the default.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Nov 7, 2025
@xSetech xSetech marked this pull request as ready for review November 7, 2025 08:24
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 7, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@xSetech
Copy link
Contributor Author

xSetech commented Nov 7, 2025

I've tested the default is set locally (x86_64-apple-darwin), but it'd be great if a CI job on an *-apple-darwin worker could also confirm.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 7, 2025

@bors try jobs=aarch64-apple

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 7, 2025
bootstrap: respect `build.python` on macOS

try-job: aarch64-apple
Comment on lines 1526 to 1539
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both branches are now much more similar than before your change, which makes me wonder where the difference went. Or maybe the default is good for most non-Windows systems generally?

Copy link
Member

@jieyouxu jieyouxu Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR actually makes them more consistent, in that now for *-apple-darwin vs non *-apple-darwin targets we both first try to use an explicitly configured build.python, then we try our luck of discovering an environmental Python. Or in the case of *-apple-darwin, the matter of "environmental python" is currently still hijacked due to lldb reasons cf. #148361 #123621 #134682.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which I agree is good, but makes me think perhaps we can go even further then? "/usr/bin/python3/ is a good default on many (most?) linux systems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I don't have build.python set and bootstrap still works for me on Linux, so some other place also sets a default python?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would work for all cases, and I would prefer to keep the scope of this PR focused. I think we'd be open for a follow-up PR, though I cannot say I know for sure /usr/bin/python3 is universally valid. For instance, picking up a python3 from PATH is also a reasonable choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I don't have build.python set and bootstrap still works for me on Linux, so some other place also sets a default python?

It's ultimately set here:
https://github.com/rust-lang/rust/blob/1.91.0/src/bootstrap/src/core/sanity.rs#L166

Note that BOOTSTRAP_PYTHON is the interpreter invoking bootstrap.py, which is itself called by x.py. x.py can actually choose a different Python than what it's invoked with, e.g. switching from Python 2 if it finds a Python 3 install:
https://github.com/rust-lang/rust/blob/1.91.0/x.py#L18

build.python should be available to override all of that guesswork, except it (and all of the indirection) were ignored by a hardcoded value on macOS. This PR fixes that particular issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @xSetech! So that makes me think finding the right python is already happening in sanity.rs, except it would fail is the PATH does not have "/usr/bin/" at higher priority than some other path that contains a python install. What does your path look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just removed both branches and inlined the .expect call at call sites, which seems much cleaner given what sanity.rs as a module already does for other tools.

@hkBst The logic in sanity.rs isn't guaranteed to choose a Python version that actually works. Python and LLVM from Homebrew are first in my path and those are the correct choices for my particular setup, so I will ultimately set build.python and override the choice sanity.rs would otherwise make. Given all that, I think there could be a bigger discussion about the heuristics it applies, and perhaps a follow-up PR might better extend the set of checks performed in sanity.rs (e.g. to verify that any chosen Python can actually load the LLDB module).

@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

This PR modifies bootstrap.example.toml.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@jieyouxu jieyouxu self-assigned this Nov 7, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @xSetech! I'll r+ once the try job comes back.

View changes since this review

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 7, 2025

💔 Test for 37f35bb failed: CI. Failed jobs:

@jieyouxu
Copy link
Member

jieyouxu commented Nov 7, 2025

Curious, I'll take a look tmrw at how they are wired together 🤔

@xSetech
Copy link
Contributor Author

xSetech commented Nov 7, 2025

sanity::check actually picks a Python interpreter before lib::python. It's complicated having more than one place where the interpreter is set, so I'll consolidate the logic that chooses a Python interpreter and refactor. That should fix the latest test result in #148646.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-testsuite Area: The testsuite used to check the correctness of rustc label Nov 7, 2025
@xSetech xSetech requested a review from hkBst November 7, 2025 21:10
@xSetech xSetech requested a review from jieyouxu November 7, 2025 21:10
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
spellchecking files
building external tool typos from package typos-cli@1.38.1
finished building tool typos
npm WARN deprecated puppeteer@22.15.0: < 24.10.2 is no longer supported
npm ERR! code 127
npm ERR! git dep preparation failed
npm ERR! command /node/bin/node /node/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/user/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
npm ERR! npm WARN deprecated debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm ERR! npm WARN deprecated read-package-json@2.1.2: This package is no longer supported. Please use @npmcli/package-json instead.
npm ERR! npm WARN deprecated read-installed@4.0.3: This package is no longer supported.
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/user/.npm/_cacache/tmp/git-cloneXXXXXXHNt2wb/node_modules/rollup
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c patch-package
npm ERR! npm ERR! sh: 1: patch-package: not found
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T21_15_36_243Z-debug-0.log

npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T21_15_29_270Z-debug-0.log
npm install did not exit successfully
tidy [extra_checks]: IO error: npm install returned exit code exit status: 127
tidy [extra_checks]: FAIL
tidy: The following check failed: extra_checks
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/npm --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1549:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1279:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:03:08
  local time: Fri Nov  7 21:16:03 UTC 2025
  network time: Fri, 07 Nov 2025 21:16:03 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

@xSetech
Copy link
Contributor Author

xSetech commented Nov 7, 2025

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

Tidy CI job failures were widespread, see:
https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/CI.20keeps.20failing.20because.20of.20npm.20error/with/554424216

@Zalathar
Copy link
Member

Zalathar commented Nov 8, 2025

I wonder how viable it is to change debuginfo tests to use lldb's embedded Python (via the lldb script command), instead of having to coordinate an external Python version that happens to be compatible.

@Zalathar
Copy link
Member

Zalathar commented Nov 8, 2025

I wonder how viable it is to change debuginfo tests to use lldb's embedded Python (via the lldb script command), instead of having to coordinate an external Python version that happens to be compatible.

To answer my own question, it seems very viable:

If we can consistently use LLDB's embedded Python, that should make build.python irrelevant to LLDB debuginfo tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants